﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using OpenChart.Entities;

namespace WinForm
{
    public partial class FormDotChart : Form
    {
        public FormDotChart()
        {
            InitializeComponent();
            this.AddTestData();
            this.InitChart();
        }

        private void AddTestData()
        {
            DataRow newRow = null;
            for (int i = 0; i < 10; i++)
            {
                newRow = this.dsTest1.Tables[0].NewRow();
                newRow["F_X"] = DateTime.Now.AddHours(i);
                newRow["F_Y1"] = i * i;
                this.dsTest1.Tables[0].Rows.Add(newRow);
            }
        }

        private void InitChart()
        {
            this.chart1.BackColor = Color.Black;

            this.chart1.ChartArea.ChartType = Enums.ChartType.Dot;
            this.chart1.ChartArea.Data = this.dsTest1.Tables[0];
            this.chart1.ChartArea.XValueMember = "F_X";

            StringInfo chartTitle = new StringInfo();
            chartTitle.Value = "LineChart";
            chartTitle.Color = Color.DarkBlue;
            chartTitle.Size = 15;
            this.chart1.ChartArea.ChartTitle = chartTitle;

            this.chart1.ChartArea.AxisLineColor = Color.DarkSeaGreen;
            this.chart1.ChartArea.AxisLineWidth = 2;

            PartingLine line = new PartingLine();
            line.YValue = 50;
            line.LineColor = Color.GreenYellow;
            this.chart1.ChartArea.PartingLines.Add(line);

            StringInfo axisXLable = new StringInfo();
            axisXLable.Size = 12;
            axisXLable.Color = Color.Silver;
            axisXLable.Value = "时间";
            this.chart1.ChartArea.AxisX.Lable = axisXLable;

            this.chart1.ChartArea.AxisX.Interval = 1;
            this.chart1.ChartArea.AxisX.IntervalType = Enums.InervalType.Hours;
            this.chart1.ChartArea.AxisX.TimeFormat = "MM-dd HH:mm";
            this.chart1.ChartArea.AxisX.Grid.LineColor = Color.RosyBrown;
            this.chart1.ChartArea.AxisX.Grid.LineStyle = Enums.LineStyle.DashDot;
            this.chart1.ChartArea.AxisX.ShowGrid = true;

            StringInfo axisYLable = new StringInfo();
            axisYLable.Size = 12;
            axisYLable.Color = Color.Silver;
            axisYLable.Value = "数据";
            this.chart1.ChartArea.AxisY1.Lable = axisYLable;

            this.chart1.ChartArea.AxisY1.Interval = 10;
            this.chart1.ChartArea.AxisY1.IntervalType = Enums.InervalType.Number;
            this.chart1.ChartArea.AxisY1.Grid.LineColor = Color.SaddleBrown;
            this.chart1.ChartArea.AxisY1.Grid.LineStyle = Enums.LineStyle.DashDot;
            this.chart1.ChartArea.AxisY1.ShowGrid = true;

            Series series1 = new Series();
            series1.Name = "SeriesOne";
            series1.Color = Color.Red;
            series1.Width = 4;//最小设置为2，再小了看不见了
            series1.YValueMember = "F_Y1";
            this.chart1.ChartArea.Series.Add(series1);
        }
    }
}
